#ifndef IO_BYTESTREAM_H
#define IO_BYTESTREAM_H

#include <deque>
#include <utility>

using std::deque;
using std::pair;

struct ValidRange {
  ValidRange(int size);
  int size() const;
  int start;
  int end;
};

class ByteStream {
 public:
  ByteStream();
  ~ByteStream();
  void Push(const char* buff, int size);
  void InsertHead(const char* buff, int size);
  void Pop(char* buffer, int size);
  void Pop(int size);
  int size();
  bool PeekInt(int* result);
  bool PeekTwoInt(int* i1, int* i2);
  void Peek(char* buffer, int size);

 private:
  typedef deque<pair<char*, ValidRange> > Queue;
  void Peek(char* buffer, int size, Queue::const_iterator iter);
  int size_;
  Queue v;
};

#endif
